home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / migd / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  1.5 KB  |  64 lines

  1. /* 
  2.  * util.c --
  3.  *
  4.  *    General utilities for the migration daemon.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/util.c,v 1.2 90/02/28 10:54:46 douglis Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <syslog.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <errno.h>
  24. #include <migd.h>
  25.  
  26. extern int debug;
  27.  
  28.  
  29. /*
  30.  *----------------------------------------------------------------------
  31.  *
  32.  * Malloc --
  33.  *
  34.  *    Centralized location for calling malloc and checking for
  35.  *    out of memory error.  
  36.  *
  37.  * Results:
  38.  *    A pointer to the allocated memory is returned.  NULL is never
  39.  *    returned.
  40.  *
  41.  * Side effects:
  42.  *    If out of memory, we panic if debugging is enabled or exit
  43.  *    otherwise.
  44.  *
  45.  *----------------------------------------------------------------------
  46.  */
  47.  
  48. char *
  49. Malloc(numBytes)
  50.     int numBytes;    /* How many bytes to allocate. */
  51. {
  52.     char *buffer;
  53.  
  54.     buffer = malloc(numBytes);
  55.     if (buffer == (char *) NULL) {
  56.     SYSLOG0(LOG_ERR, "Out of memory!  Exiting.");
  57.     if (debug) {
  58.         panic("Out of memory.\n");
  59.     }
  60.     exit(ENOMEM);
  61.     }
  62.     return(buffer);
  63. }
  64.